<template>
  <div class="ek-dialog">
    <el-dialog v-model="visiable"  ref="ekdialog">
      <template #header>
        <div class="ek-dialog-title">
            <slot name="header"> 
              {{ ekTitle }}
            </slot>
        </div>
      </template>
      <div class="ek-dialog-body">
        <slot></slot>
      </div>
      <template #footer>
        <div class="ek-dialog-footer" v-if="!hideBtn">
            <slot name="footer"> 
                <el-button type="primary" @click.stop="handleClose">取消</el-button>
                <el-button type="primary" @click.stop="handleSubmit">确定</el-button>
             </slot>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import {
  defineComponent,
  onMounted,
  getCurrentInstance,
  ref,
  reactive,
  computed,
} from "vue";

import { useStore } from "vuex";
import { useRouter } from "vue-router";

const props = defineProps({
  // 显示/隐藏
  modelValue: {
    type: Boolean,
    default: false,
  },
  // 标题
  title: {
    type: String,
    default: "",
  },
  // 是否隐藏操作按钮
  hideBtn: {
    type: Boolean,
    default: false,
  },
});

const {
  appContext: {
    config: { globalProperties },
  },
} = getCurrentInstance();

const { $storage, $http } = globalProperties;
const store = useStore();
const router = useRouter();

const emit = defineEmits(["update:modelValue", "submit"]);
const visiable = computed({
  get() {
    return props.modelValue;
  },
  set(value) {
    emit("update:modelValue", value);
  },
});
const ekTitle = computed({
  get() {
    return props.title;
  },
});

const ekdialog = ref(null);
function handleClose() {
  visiable.value = false
}

function handleSubmit() {
  emit("submit", () => {
    handleClose();
  });
}
</script>

<style scoped lang="scss">
.ek-dialog {
    .ek-dialog-title {
        font-size: 16px;
        text-align: left;
        border-bottom: 1px solid #efeff5;
        padding-bottom: 16px;
    }
  .ek-dialog-footer {
    padding-top: 16px;
    box-shadow: 0px -2px 0 rgba(0, 0, 0, .04);

  }
  :deep(.el-dialog__body) {
    height: 56vh;
    overflow: auto;
  }
}
@media screen and (max-width: 1024px) {
    :deep(.el-dialog) {
        width: 92%;
    }
}
</style>
